#ifndef _LINUX_CHECKPOINT_TYPES_H_
#define _LINUX_CHECKPOINT_TYPES_H_
/*
 *  Generic checkpoint-restart
 *
 *  Copyright (C) 2008-2009 Oren Laadan
 *
 *  This file is subject to the terms and conditions of the GNU General Public
 *  License.  See the file COPYING in the main directory of the Linux
 *  distribution for more details.
 */

#include <proc.h>
#include <slab.h>
#include <string.h>
#include <sync.h>
#include <pmm.h>
#include <error.h>
#include <sched.h>
#include <elf.h>
#include <vmm.h>
#include <trap.h>
#include <unistd.h>
#include <stdio.h>
#include <sched.h>
#include <stdlib.h>
#include <assert.h>
#include <elf.h>
#include <fs.h>
#include <sync.h>
#include <vfs.h>
#include <sysfile.h>
#include <swap.h>
#include <mbox.h>
#include <kio.h>
#include <stdio.h>
#include <mp.h>
#include <map.h>

struct ckpt_ctx {
	int crid;			/* unique checkpoint id */

	int ktime_begin;		/* operation start time */ // U11 : ticks??? TODO : fix to time

	struct proc_struct *root_task;		/* [container] root task */
	struct inode* root_fs_path;	/* container root (FIXME) */

	unsigned long kflags;		/* kernel flags */
	unsigned long uflags;		/* user flags */
	unsigned long oflags;		/* [restart] uflags from checkpoint */

	int file_d;  /* input/output file */
	int logfile_d;  /* status/debug log file */
	off_t total;			/* total read/written */

	atomic_t refcount;

	int errno;			/* errno that caused failure */

//	struct ckpt_stats stats;	/* statistics */


	// proc resource
	struct proc_struct **tasks_arr;	/* array of all tasks */
	int nr_tasks;			/* size of tasks array */
	struct map proc_map;

	// memory struct
	struct map mm_map;

	// shared memory resource
	struct map shared_mm_map;

	// file resource
	struct map fs_map;

	// timer resource
	struct map timer_map;

	// especially, stdin, stdout

	// signal...

	/* [checkpoint] */
//	struct proc_struct *tsk;	/* current target task */
//
//	/* [restart] */
//	int active_task;		/* (next) position in pids array */
//	atomic_t nr_total;		/* total tasks count */
//	struct completion complete;	/* completion for container root */
//	wait_queue_head_t waitq;	/* waitqueue for restarting tasks */
//	wait_queue_head_t ghostq;	/* waitqueue for ghost tasks */
//	struct cred *realcred, *ecred;	/* tmp storage for cred at restart */
//	struct list_head listen_sockets;/* listening parent sockets */
//
#define CKPT_MSG_LEN 1024
	char fmt[CKPT_MSG_LEN];
	char msg[CKPT_MSG_LEN];
	int msglen;
	sem_t msg_mutex;
};

// storage format
#define CKPT_CHUNK_MAGIC 0x123123

struct ckpt_chunk_header
{
	uint32_t chunk_magic;
	uint32_t chunk_type;
	uint32_t chunk_len;
};

#define CKPT_CHUNK_TYPE_HEADER 1
struct ckpt_header
{
	uint32_t arch_id; // architecture of the ckpt machine
	uint32_t version; // version of checkpoint
	uint32_t linux_version; // version of linux

	uint32_t uflags;
	uint64_t time; // checkpoint time
};

#define CKPT_CHUNK_TYPE_TASK 2
struct ckpt_task_header
{
	uint32_t task_count; // number of tasks

};

#define CKPT_CHUNK_TYPE_MM 3
struct ckpt_mm_header
{
	uint32_t mm_count; // number of mms

};

#define CKPT_CHUNK_TYPE_SHAREDMM 4
struct ckpt_shared_mm_header
{
	uint32_t shared_mm_count;
};

#define CKPT_CHUNK_TYPE_FS 5
struct ckpt_fs_header
{
	uint32_t fs_count; // number of mms

};

#define CKPT_CHUNK_TYPE_TRAPFRAME 6

#define CKPT_CHUNK_TYPE_TIMER 7


struct ckpt_mm_dump_struct
{
	uint32_t vma_struct_count; // number of vma_structs
};

#endif /* _LINUX_CHECKPOINT_TYPES_H_ */

